﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Next.CodeGen.Core.Generators;
using Next.CodeGen.Core.Utility;
namespace Next.CodeGen
{
    class Program
    {
        /// <summary>
        /// The operation you want to perform :
        ///     Clean [Clear Options : defaut -all] [Table Names]
        ///         - Options :
        ///             -all : Cleans all generated data
        ///             -schema : Cleans the schema xml file
        ///             -forms : Cleans the generated xaml and cs files of the selected Tables.
        ///                 Use : Clean -forms [Table Names]
        ///                 
        ///     GenerateSchema : Generates the schema for the selected Project DataBase
        ///     
        ///     GenerateForms : Generates the user controls for each column of each table
        ///         Use : GenerateForms [Table Names]
        ///         
        ///     GenerateValidators : Generates Field Maximum Length and Mandatory Fields Validators
        ///         Use : GenerateValidators [Table Names]
        ///         
        ///     Localize : Add resx files to globalize culture of the application
        ///         Use : Localize {Options}
        ///             - Options :
        ///                 -enabled {true/false}
        ///                 -register-culture {ISO-culture}
        ///                 -unregister-cuture {ISO-culture}
        ///                 -set-default-culter {ISO-culture}
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //COND : Arguments passed
            if (args.Count() > 0)
            {
                switch (args[0].ToLower())
                {
                    case "generateschema":
                        #region GenerateSchema
                        Schema.GenerateSchema();
                        #endregion
                        break;
                    case "generateforms":
                        #region GenerateForms
                        if (args.Count() == 1)
                        {
                            Forms.GenerateForms(null);
                        }
                        else
                        {
                            Forms.GenerateForms(args.Skip(1).ToList<string>());
                        }
                        #endregion
                        break;
                    case "clean":
                        #region clean
                        if (args.Count() == 1)
                        {
                            Clean.CleanAll();
                        }
                        else
                        {
                            switch (args[1].ToLower())
                            {
                                case "-all":
                                    Clean.CleanAll();
                                    break;
                                case "-schema":
                                    Clean.CleanSchema();
                                    break;
                                case "-forms":
                                    Clean.CleanForms(args.Skip(2).ToList<string>());
                                    break;
                                default:
                                    Help.CommandLineError();
                                    break;
                            }
                        }
                        #endregion
                        break;
                    case "-help":
                    case "?":
                        #region Help
                        if (args.Count() == 1)
                        {
                            Console.WriteLine("All Help");
                        }
                        else
                        {
                            //switch (args[1].ToLower())
                            //{

                            //}
                        }
                        #endregion
                        break;
                    default:
                        Help.CommandLineError();
                        break;
                }
            }
            //COND : No argument passed
            else
            {
                //XMLSchemaUtility.XMLToList();
               
                //Schema.GenerateSchema();
                Forms.GenerateForms(null);
                //Clean.CleanSchema();
                //Clean.CleanForms(null);
            }
        }
    }
}
